package com.bwie.goods.controller;

import com.bwie.common.domain.Goods;
import com.bwie.common.result.Result;
import com.bwie.goods.service.GoodsService;
import com.bwie.goods.util.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/good")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @PostMapping("/findGoodList")
    public Result findGoodList(@RequestBody Goods goods){
        List<Goods> goodList = goodsService.findGoodList(goods);
        return Result.success(goodList);
    }

    @PostMapping("/addGood")
    public Result addGood(@RequestBody Goods goods){
        Result result = goodsService.addGood(goods);
        return result;
    }

    @GetMapping("/delGood/{id}")
    public Result delGood(@PathVariable Integer id){
        Result result = goodsService.delGood(id);
        return result;
    }

    @RequestMapping("/exportFileAll")
    public void exportFileAll(HttpServletResponse response){
        ExcelUtil<Goods> goodsExcelUtil = new ExcelUtil<>(Goods.class);
        List<Goods> list = goodsService.findList();
        goodsExcelUtil.exportExcel(response,list,"商品列表");
    }


}
